/**
 * @Author: Sun Rising
 * @Date: 2022-01-01 11:11:38
 * @Last Modified by: Sun Rising
 * @Last Modified time: 2022-01-02 10:59:41
 * @Description: electron 工具
 */

import { app } from "electron";

/**
 * 通过 URL 下载文件，打开文件保存窗口
 * @param url 文件地址
 * @param title 保存框标题
 */
export function saveFileByUrl(url: string, title?: string) {
  console.log(url);
  console.log(app.getPath("temp"));
  for (let index = 0; index < 100; index++) {
    console.log(uuidV4());
  }
}

/**
 * 创建uuidV4
 * @returns uuid字符串
 */
export default function uuidV4() {
  // 默认M为4
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
    const r = (Math.random() * 16) | 0; // 取整
    const v = c === "x" ? r : (r & 0x3) | 0x8;
    return v.toString();
  });
}
